Page({
  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: [
      'https://mfs.ys7.com/mall/e98d038900534dbe1aed67f5492c9ea9.jpg?5790596340',
      'https://mfs.ys7.com/mall/04bae0aad0d0d221abf003fa078a5ce9.jpg?9578041615',
      'https://mfs.ys7.com/mall/85343c2d2145dc43add6925de083ab83.png?9578041615',
      'https://mfs.ys7.com/mall/391a5b9bf00e653e75414be76a516127.jpg?5790596340',
      'https://mfs.ys7.com/mall/25aac160843f48025c613a2cc2f59c91.jpg?9578041615',
      'https://mfs.ys7.com/mall/d2a8ab6755658f837a213d2b22e07a0a.jpg?9578041615'
    ],
    interval: 5000,
    duration: 1000,
    list:[],
    listType:[],
    listRx:[],
    pageing:{
      current:1,
      pageSize:6,
      total:0
    },
    totalPage:0,
    isEnd:false
  },
  // 我要选商品
  selShop(){
    wx.navigateTo({
      url: '../selShop/selShop',
    })
  },
  // 下面循环的跳转
  swipImg:function(e){
    let objItem = e.currentTarget.dataset.item
   wx.setStorage({
     key: 'zxwx-objItem-1902',
     data: objItem,
   })
    wx.navigateTo({
      url: '../swip/swip',
    })
  },
  // 热销页面 跳转
  swipDelis:function(e){
    let objItem = e.currentTarget.dataset.item
    wx.setStorage({
      key: 'zxwx-objItem-1902',
      data: objItem,
    })
    wx.navigateTo({
      url: '../swip/swip',
    })
  },
  // 渲染 热销推荐 页面
  getReXiao:function(){
    let url = 'http://localhost/api/api.php/yingshi/tzzq'
    wx.request({
      url,
      method:'get',
      data:{
        transform:1
      },
      success:res=>{
        this.setData({
          listRx: res.data.tzzq
        })
      }
    })
  },
  // 渲染页面
  getData:function(){
    if (this.data.totalPage!=0 && this.data.current == this.data.totalPage){
      this.setData({
        isEnd:true
      })
      return
    }
    wx.showLoading({
      title: '拼命加载中...',
    })
    let { current, pageSize } = this.data.pageing
    let url = 'http://localhost/api/api.php/yingshi/ysscshops'
    wx.request({
      url,
      method:'get',
      data:{
        transform:1,
        order:'id,desc',
        page:`${current},${pageSize}`
      },
      success:res=>{
        this.setData({
          list: [...this.data.list, ...res.data.ysscshops],
          total:Math.ceil(res.data._results / pageSize)
        })
        this.data.totalPage = this.data.total
        wx.hideLoading()
        wx.stopPullDownRefresh()
        wx.hideNavigationBarLoading()
  
      }
    })
  },
  // 渲染页面  ==  类型
  getType:function(){
    wx.showLoading({
      title: '拼命加载中...',
    })
   let url = 'http://localhost/api/api.php/yingshi/yssctype'
    wx.request({
      url,
      method:'get',
      data: {
       transform:1, 
      },
      success:res=> {
        this.setData({
          listType: res.data.yssctype
        })
        wx.hideLoading()
      }
    })
  },
  /**
   * 生命周期函数-监听页面加载
   */
  onLoad: function (options) {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getType()
    this.getReXiao()
    this.getData()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    pageing: {
      this.data.pageing.current = 1
    }
    this.setData({
      isEnd: false
    })
    wx.showNavigationBarLoading()
    this.getData()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    pageing: {
      this.data.current = ++this.data.pageing.current
    }
    this.getData()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})